<template>
	<page-card title="基本信息登记"
						 sub-title="合同列表"
						 :need-back="true"
						 class="table-page-search-wrapper">
		<a-form :form="form"
						layout="inline">
			<a-row type="flex"
						 :gutter="[15]">
				<a-col :span="16">
					<a-form-item label="合同名称">
						<a-input v-decorator="[
                'contractName',
                {
                  rules: [
                    {
                      required: true,
                      message: '请输入合同名称',
                    },
                  ],
                },
              ]" />
					</a-form-item>
				</a-col>

				<a-col :span="8">
					<a-form-item label="合同编号">
						<a-input v-decorator="[
                'contractId',
                {
                  rules: [{ required: true, message: '请输入合同编号' }],
                },
              ]" />
					</a-form-item>
				</a-col>
			</a-row>
			<a-row type="flex"
						 :gutter="[6,6]">
				<a-col :span="8">
					<a-form-item label="合同金额">
						<a-input v-decorator="[
                'contractAnt',
                {
                  rules: [
                    {
                      required: true,
                      message: '请输入金额',
                      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
                      message: '请输入正确金额格式',
                    },
                  ],
                },
              ]" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="签订日期"
											 layout="inline">
						<a-date-picker v-decorator="[
                'signDate',
                {
                  rules: [
                    {
                      type: 'object',
                      required: true,
                      message: '请选择日期',
                    },
                  ],
                },
              ]"
													 show-time
													 format="YYYY-MM-DD"
													 type="date"
													 style="width: 100%" />
					</a-form-item>
				</a-col>

				<a-col :span="8">
					<a-form-item label="合同日期">
						<a-date-picker v-decorator="[
                'contractDate',
                {
                  rules: [
                    {
                      type: 'object',
                      required: true,
                      message: '请选择日期',
                    },
                  ],
                },
              ]"
													 show-time
													 format="YYYY-MM-DD"
													 type="date"
													 style="width: 100%" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row type="flex"
						 :gutter="[16]"
						 style="margin-left: 3px">
				<a-col :span="8">
					<a-form-item label="甲方单位">
						<a-input v-decorator="['coopUnit', {}]" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="联系人">
						<a-input v-decorator="[
                'contacts',

              ]" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="联系电话">
						<a-input v-decorator="[
                'contactNumber',
                {
                  rules: [],
                },
              ]" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row type="flex"
						 :gutter="[48]">
				<a-col :span="8">
					<a-form-item label="项目类型">
						<a-select v-decorator="
              [
                'proType',
                {
                  rules: [
                    {
                      required: true,
                      message: '请选择项目类型',
                    },
                  ],
                },
              ]">
							<a-select-option value="1">开发项目1</a-select-option>
							<a-select-option value="2">运维项目2</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="16">
					<a-form-item label="项目规模">
						<a-radio-group v-decorator="['proSca']">
							<a-radio value="1"> 大型 </a-radio>
							<a-radio value="2"> 中型 </a-radio>
							<a-radio value="3"> 小型 </a-radio>
						</a-radio-group>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row type="flex"
						 :gutter="[15,15]"
						 style="margin-left: 3px">
				<a-col :span="8">
					<a-form-item label="客户经理">
						<a-input v-decorator="[
                'customerManeger',
                {
                  rules: [{
                  }],
                },
              ]" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="承担部门">
						<a-select @change="clearManger"
											v-decorator="[
                'unitA',
                {
                  rules: [],

                },
              ]">
							<a-select-option value="1"> 软件一部 </a-select-option>
							<a-select-option value="2"> 软件二部 </a-select-option>
							<a-select-option value="3"> 软件三部 </a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="项目经理">
						<a-input v-decorator="
              [
                'projectManege',
                {
                  rules: [
                    {
                      required: IsEmpty,
                      message: '请输入项目经理',
                    },
                  ],
                },
              ]" />
					</a-form-item>
				</a-col>
			</a-row>
			<a-row type="flex"
						 :gutter="[15]"
						 style="height: 50px; margin-left: 33px">
				<a-col flex="1">
					<a-form-item label="备注">
						<a-textarea v-decorator="[
                'detil',
                {
                  rules: [],
                },
              ]"
												:auto-size="{ minRows: 3, maxRows: 5 }" />
					</a-form-item>
				</a-col>
			</a-row>
			<!--button-->
			<a-row type="flex"
						 :gutter="[16]"
						 style="margin-top: 100px"
						 justify="center">
				<a-col :span="8">
					<a-button type="primary"
										style="background-color: green"
										@click="handleSave()">
						保存
					</a-button>
				</a-col>
				<a-col :span="8">
					<a-button type="primary"
										@click="ToContractList()"> 返回 </a-button>
				</a-col>
			</a-row>
		</a-form>
	</page-card>
</template>

<script>
import { contractSaveOrUpdate } from '@/api/contract'
export default {
	components: {},
	data() {
		return {
			form: this.$form.createForm(this),
			//项目经理是否不为空,默认可以不为空
			IsEmpty: false
		}
	},
	mounted() {},
	methods: {
		clearManger(value) {
			//部门改变，清空项目经理
			this.form.setFieldsValue({ projectManeger: '' })
			console.log(value)

			if (value != '' || value != undefined) {
				//默认值
				this.IsEmpty = true
			}
		},

		//返回合同列表页面
		ToContractList() {
			this.$router.go(-1)
		},
		handleSave() {
			this.form.validateFieldsAndScroll((err, values) => {
				if (err) {
					return
				}
				console.log(values)
				contractSaveOrUpdate(values).then((response) => {
					this.message.success('保存成功')
					this.$router.go(-1)
				})
			})
		}
	}
}
</script>

<style>
</style>
